package com.ruif.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.ruif.model.User;

public class UserDAO
{

    /**
     * 登录验证，返回 User 对象
     * 
     * @param conn
     * @param user
     * @return
     * @throws Exception
     */
    public User login(Connection conn, User user) throws Exception
    {
        User resultUser = null;
        String sql = "select * from t_user where name=? and password=?";
        PreparedStatement stmt = conn.prepareStatement(sql);
        stmt.setString(1, user.getName());
        stmt.setString(2, user.getPassword());
        ResultSet rs = stmt.executeQuery();
        while (rs.next())
        {
            resultUser = new User();
            resultUser.setName(rs.getString("name"));
            resultUser.setPassword(rs.getString("password"));
        }
        return resultUser;
    }

}
